package net.tester.testing.powermockito;

import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;
import javax.naming.InitialContext;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

@RunWith(PowerMockRunner.class) 
@PrepareForTest({ BaseClass.class, InitialContext.class })
public class EqualsTest {
	//having problems - This test case is not working due to problems when trying to stub the "equals" method.
	@Test      
	public void myMockEquals() throws Exception {          
		BaseClass mockBaseClass = mock(BaseClass.class);	
		when(mockBaseClass.equals(mockBaseClass)).thenReturn(true);            
		Assert.assertTrue(mockBaseClass.equals(mockBaseClass));      
	}
	
	//works
	@Test      
	public void myMockEquals2() throws Exception {          
		BaseClass mockBaseClass = mock(BaseClass.class);	
		when(mockBaseClass.equals2(mockBaseClass)).thenReturn(true);            
		Assert.assertTrue(mockBaseClass.equals(mockBaseClass));      
	}
	
	//works
	@Test      
	public void shouldMockEqualsExample() throws Exception {          
		InitialContext context = mock(InitialContext.class);          
		when(context.equals(context)).thenReturn(true);            
		Assert.assertTrue(context.equals(context));      
	}
}
